<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Customer</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="" lay-filter="table-search">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">渠道</label>
                            <div class="layui-input-inline">
                                <select name="channelType" class="layui-select">
                                    <option value="12">青衣</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">长ID</label>
                            <div class="layui-input-inline">
                                <input type="number" name="customerId" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">登录账号</label>
                            <div class="layui-input-inline">
                                <input type="text" name="phone" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">真实姓名</label>
                            <div class="layui-input-inline">
                                <input type="text" name="realName" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">渠道ID[换行]</label>
                            <div class="layui-input-inline">
                                <textarea name="channel_uuid"></textarea>
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">邀请码</label>
                            <div class="layui-input-inline">
                                <input type="text" name="invite_code" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">长id[换行]</label>
                            <div class="layui-input-inline">
                                <textarea name="customerIds"></textarea>
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">账号[换行]</label>
                            <div class="layui-input-inline">
                                <textarea name="phones"></textarea>
                            </div>
                        </div>

                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

    </div>
</div>

<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="export" auth="customer:export">导出</button>
        <button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="add" auth="customer:add">添加</button>
        <button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="autoGen" auth="customer:autoGen">官方账号生成</button>
    </div>
</script>

<script type="text/html" id="currentTableBar">

</script>

<script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/js/common.js?v=5" charset="utf-8"></script>
<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        var searchParams = {
            channelType: 12
        };
        table.render({
            elem: '#currentTableId',
            url: '/admin/customerqy/paginate?' + $.param(searchParams),
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'print'],
            cols: [[
                {type: "checkbox", width: 50},
                {field: 'uuid', width: 180, title: 'ID', sort: true},
                {field: 'channel_type', title: '账号渠道',templet:function(row){
                    if(row.channel_type===1) return '官方'
                    if(row.channel_type===2) return '抖音'
                    if(row.channel_type===3) return '易游'
                        if(row.channel_type===12) return '青衣'
                        if(row.channel_type===11) return '辰画'
                        if(row.channel_type===10) return 'QQ大厅'
                        return '未知'
                }},
                {field: 'phone', width: 200,title: '手机号'},
                {field: 'mobile', width: 200,title: '绑丁手机号'},
                {field: 'package_no', title: '包号'},
                {field: 'invite_code',  title: '填写的邀请码'},
                {field: 'channel_uuid',  title: '渠道ID'},
                {field: 'real_name', title: '真实姓名' },
                {field: 'identity_code', title: '身份证号码' },
                {field: 'created_at', title: '创建时间'},
                {field: 'lastloginserverid', title:'最后登录区服' },
                {field: 'logindata', title:'最后登录时间' },
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true,
            skin: 'line'
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var searchData = data.field;
            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where:searchData
            }, 'data');
            return false;
        });

        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            var selectedData = table.checkStatus(obj.config.id).data;
            var ids = selectedData.map(function(data) {
                return data.uuid;
            }).join(',');
            console.log('组装的id',ids)
            if (obj.event === 'add') {  // 监听添加操作
                layer.open({
                    title: '添加用户',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['600px', '500px'],
                    content: 'edit.html',
                });
            } else if(obj.event === 'export'){ //导出
                var searchData = form.val('table-search');
                searchData.page = 1;
                searchData.limit = 9999999;
                asyncDownload(
                    '/admin/customer/export',
                    searchData,
                    {token:localStorage.getItem('adminToken')}
                );
            } else if(obj.event==='autoGen'){
                layer.open({
                    title: '账号自动生成',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['600px', '500px'],
                    content: 'autoGen.html',
                });
            }

            else if(obj.event==='edits'){
                layer.open({
                    title: '账号自动生成',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['600px', '500px'],
                    content: 'editCodeInfos.html?id='+ids,
                });
            }
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'delete') {
                layer.confirm('真的删除行么', function (index) {
                    var ids = [data.id];
                    $.post("/admin/customer/delete",{'_method':'delete',ids:ids},function(res){
                        if (res.code ===0 ){
                            layer.msg('删除成功')
                            obj.del();
                            layer.close(index);
                        }
                    })
                });
            } else if(obj.event==='resetPass'){
                layer.open({
                    title: '重置密码',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['600px', '500px'],
                    content: 'resetPass.html?id='+data.uuid,
                });
            } else if(obj.event==='showPass'){
                $.get('/admin/customer/'+data.uuid+"/showPass",{},function (res) {
                    if (res.code===0){
                        layer.open({
                            title: '密码',
                            type: 1,
                            shade: 0.2,
                            maxmin:true,
                            shadeClose: true,
                            area: ['200px', '100px'],
                            content: res.data.password
                        });
                    } else {
                        layer.msg(res.msg,{icon:2})
                    }
                })

            }
            else if(obj.event==='edit'){
                layer.open({
                    title: '修改用户信息',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['600px', '500px'],
                    content: 'editInfo.html?id='+data.uuid,
                });
            }
            else if(obj.event==='editcode'){
                layer.open({
                    title: '修改用户邀请码',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['600px', '500px'],
                    content: 'editCodeInfo.html?id='+data.uuid,
                });
            }
        });
    });
</script>
</body>
</html>